package com.infinit.easyreader.Biz;

import android.content.Context;
import android.os.Handler;

import com.infinit.easyreader.dao.RankDao;
import com.infinit.easyreader.entity.RankTime;
import com.infinit.easyreader.entity.RankType;
import com.infinit.easyreader.utils.Consts;

import java.util.HashMap;
import java.util.Map;

/**
 * 类：com.infinit.easyreader.Biz.RecommendBiz V[1.0.0]
 * 作用：从互联网获取推荐的数据
 * Created by rzy on 2016/6/29.
 */
public class RecommendBiz implements Consts {

    private Context context;
    private Map<String, String> params;
    private RankDao rankDao;
    private Handler handler;

    public RecommendBiz(Context context, Handler handler) {
        params = new HashMap<>();
        this.context = context;
        rankDao = new RankDao(context);
        this.handler = handler;
    }

    /**
     * 从数据库中获取幸运的RankId和RankTimeId
     */

    private void getParamsFromDb() {
        RankTime rankTime = rankDao.getRankTime("周排行");
        RankType rankType = rankDao.getRankType("人气排行");
        params.put("rankType", rankType.getRankTypeID() + "");
        params.put("rankTime", rankTime.getRankTimeID() + "");
        rankDao.close();
    }

    /**
     * 发送请求，从互联网请求排行数据
     */

    public void getRecommendInfoFromInternet() {
        //获取3条数据
        RankContentBiz rankContentBiz = new RankContentBiz(handler, context);
        rankContentBiz.setCount(3);
        getParamsFromDb();
        rankContentBiz.setParams(params);
        rankContentBiz.getRankContentFromInternet();
    }
}
